package com.project_doctor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project_doctor.pojo.Tag;
import com.project_doctor.service.TagService;
import com.project_doctor.mapper.TagMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author xixif
* @description 针对表【t_tag(统一标签表)】的数据库操作Service实现
* @createDate 2025-06-03 16:14:12
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag>
    implements TagService{
    @Autowired
    private TagMapper tagMapper;

    @Override
    public List<Tag> getAllTag(Integer type) {
        List<Tag> list = tagMapper.selectAllTag(type);
        return list;
    }

    @Override
    public List<Tag> getTagStatus() {
        return tagMapper.getTagStatus();
    }

    @Override
    public List<String> selectTagsList(Integer residentId) {
        LambdaQueryWrapper<Tag> dataTagWrapper = new LambdaQueryWrapper<>();
        dataTagWrapper.select(Tag::getName)
                .eq(Tag::getRefId, residentId)
                .eq(Tag::getRefType, 1);

        return tagMapper.selectList(dataTagWrapper)
                .stream()
                .map(Tag::getName) // 提取 Integer 类型
                .collect(Collectors.toList());
    }

    @Override
    public void deleteTags(Integer residentId) {
        LambdaQueryWrapper<Tag> dataTagWrapper = new LambdaQueryWrapper<>();
        dataTagWrapper.eq(Tag::getRefId, residentId)
                .eq(Tag::getRefType, 1);
        tagMapper.delete(dataTagWrapper);
    }

    @Override
    public void insertTags(Tag tagData) {
        tagMapper.insert(tagData);
    }
}




